import request from '@/utils/request';

// 获取聊天历史记录
export function getMessageHistory(negotiationId) {
    return request({
        url: `/chat/history/${negotiationId}`,
        method: 'get'
    });
}

// 发送消息
export function sendMessage(data) {
    // 如果是FormData类型（上传文件）
    if (data instanceof FormData) {
        return request({
            url: '/chat/send',
            method: 'post',
            data: data,
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        });
    }
    // 普通JSON数据
    return request({
        url: '/chat/send',
        method: 'post',
        data
    });
}

// 标记消息为已读
export function markMessageAsRead(messageId) {
    return request({
        url: `/chat/messages/${messageId}/read`,
        method: 'put'
    });
}

// 撤回消息
export function recallMessage(messageId, userId) {
    return request({
        url: `/chat/messages/${messageId}`,
        method: 'delete',
        params: { userId }
    });
} 